package com.zhuiyun.project.api.videosorting.mapper;

import com.zhuiyun.project.api.videosorting.entity.VideoSorting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName VideoSortingMapper
 * @Description 视频排序mapper接口
 * @Author zsc
 * @Date 2024/12/9 19:48
 */
public interface VideoSortingMapper {

    /**
    * @Author zsc
    * @Description 添加视频排序
    * @Date 2024/12/10 13:32
    * @Return int
    * @param videoSorting
    */
    @Insert("INSERT INTO video_sorting (sorting, title, video_id, img_id) " +
            "VALUES (#{sorting}, #{title}, #{videoId}, #{imgId})")
    int insert(VideoSorting videoSorting);

    /**
    * @Author zsc
    * @Description 查询视频排序
    * @Date 2024/12/10 13:33
    * @Return java.util.List<com.zhuiyun.project.api.videosorting.entity.VideoSorting>

    */
    @Select("SELECT vs.id,fm.create_time as createTime, vs.sorting, vs.title, vs.video_id, vs.img_id, fm.file_name " +
            "FROM video_sorting vs " +
            "LEFT JOIN file_manage fm ON vs.video_id = fm.id " +
            "ORDER BY vs.sorting ASC")
    List<VideoSorting> selectAll();


    /**
    * @Author zsc
    * @Description 根据id修改视频排序
    * @Date 2024/12/10 13:32
    * @Return int
    * @param videoSorting
    */
    @Update("UPDATE video_sorting " +
            "SET sorting = #{sorting}, " +
            "    title = #{title}, " +
            "    video_id = #{videoId}, " +
            "    img_id = #{imgId} " +
            "WHERE id = #{id}")
    int updateByPrimaryKey(VideoSorting videoSorting);

    /**
    * @Author zsc
    * @Description 根据id删除视频排序
    * @Date 2024/12/10 13:32
    * @Return int
    * @param id
    */
    @Delete("DELETE FROM video_sorting WHERE id = #{id}")
    int deleteByPrimaryKey(int id);
}
